package com.glacier.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * date 2024-01-03 16:25
 *
 * @author glacier
 * @version 1.0
 */
public class ReentrantLockDemo {
    private final static Lock LOCK = new ReentrantLock();

    public static void method1() {
        System.out.println("method1 start");
        try {
            LOCK.lock();
            System.out.println("method1 lock");
            method2();
            System.out.println("method1 running");
        } finally {
            LOCK.unlock();
            System.out.println("method1 unlock");
        }
        System.out.println("method1 end");
    }

    public static void method2() {
        System.out.println("method2 start");
        try {
            LOCK.lock();
            System.out.println("method2 lock");
        } finally {
            LOCK.unlock();
            System.out.println("method2 unlock");
        }
        System.out.println("method2 end");
    }

}
